﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
using ExtAspNet;

namespace GPCSC.Web.SHFW
{
    public partial class TZUpLoadFile : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                F_bound();
            }
        }
        protected void F_bound()
        {
            DataSet ds = new CL_TZ_S().getfile(Usual.f_querystringToString("tzid"));
            if (ds.Tables.Count > 0)
            {
                Grid1.DataSource = ds;
                Grid1.DataBind();
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string fileName = filePhoto.ShortFileName;
            fileName = fileName.Replace(":", "_").Replace(" ", "_").Replace("\\", "_").Replace("/", "_");
            string fileNames = DateTime.Now.Ticks.ToString() + "_" + fileName;
            if (filePhoto.HasFile)
            {
                filePhoto.SaveAs(Server.MapPath("~/uploadfile/" + fileNames));
                addData(fileName,fileNames);
                F_bound();
            }


        }
        protected void addData(string YfileName,string fileUrl)
        {
            GPCSC.Webs.databyhtable dh = new GPCSC.Webs.databyhtable();
            Hashtable htable = new Hashtable();
            htable.Add("TZID", Usual.f_querystringToString("tzid"));
            htable.Add("TZURL",  fileUrl);
            htable.Add("filename", YfileName);
            dh.databyhtables(htable, "add", "CL_TZFile", "", "");

        }
        protected void Grid1_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            GPCSC.Webs.databyhtable dh = new GPCSC.Webs.databyhtable();
            Hashtable htable = new Hashtable();
            foreach (int row in Grid1.SelectedRowIndexArray)
            {
                htable.Clear();
                htable.Add("isdel", 1);
                dh.databyhtables(htable, "update", "CL_TZFile", "ID", Grid1.DataKeys[row][0].ToString());
            }
            F_bound();
            Alert.Show("删除成功!");
        }

    }
}